package com.sx.pipeline.ui.login.frag

import android.net.Uri
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavCallback
import com.sx.mvvmlibs.utils.Logs
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseFragment
import com.sx.pipeline.app.config.IntentKey
import com.sx.pipeline.app.config.LoginType
import com.sx.pipeline.app.config.SmsCodeType
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.databinding.FragVerifyCodeLoginBinding
import com.sx.pipeline.repos.http.res.ContactUserVo
import com.sx.pipeline.repos.http.res.UserInfoVO
import com.sx.pipeline.ui.login.LoginPageActivity
import io.rong.imkit.RongIM
import io.rong.imlib.RongIMClient

/**
 * @Author: YY
 * @Date: 2022/4/6
 * @Description: 验证码登录
 */
class VerifyCodeLoginFragment : CYDataBindingBaseFragment<FragVerifyCodeLoginBinding, LoginVM>(
    R.layout.frag_verify_code_login
), View.OnClickListener {

    companion object {
        fun newInstance(position: Int) =
            VerifyCodeLoginFragment().apply {
                arguments = Bundle().apply {
                    putInt(IntentKey.ID, position)
                }
            }
    }

    override fun initData() {
        mBinding.setVariable(BR.onClick, this)
    }

    override fun onStart() {
        super.onStart()
    }

    override fun onPause() {
        super.onPause()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        // 验证码状态
        observe(mViewModel.smsCodeEvent) {
            mBinding.tvCountDown.start()
        }
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.tv_count_down -> {
                // 验证码
                val phone = mBinding.etPhone.text.toString()
                mViewModel.sendSmsCode(phone, SmsCodeType.LOGIN_SMS.code)
            }
            R.id.tv_register_user -> {
                // 注册
                RouteManager.Register.intentToRegSelectTypeID()


            }
            R.id.tv_forget_pwd -> {
                // 忘记密码
                RouteManager.ForgetPwd.intentToForgetPwd()
            }
            R.id.tv_login -> {
                // 登录
                if((activity as LoginPageActivity).isCheck()){
                    val phone = mBinding.etPhone.text.toString()
                    val smsCode = mBinding.etVerifyCode.text.toString()
                    mViewModel.login(LoginType.VERIFY_CODE_LOGIN.code, phone, smsCode, "")
                }

            }
        }
    }
}